package com.Service.Impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.Dao.BaseDaoI;
import com.Entity.Topiccomment;
import com.Service.TopicCommentService;
@Service("topicCommentService")
public class TopicCommentServiceImpl extends BaseServiceImpl<Topiccomment> implements TopicCommentService {

	@Autowired
	private BaseDaoI<Topiccomment> topicCommentDao;
	
	public List<Topiccomment> getTopicCommentByTopicId(long topicid,int page,int rows) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("originalTopicId", topicid);
		String hql="from Topiccomment t where t.originalTopicId=:originalTopicId order by commentTime ASC";
		return topicCommentDao.find(hql, params, page, rows);
	}

	@Override
	public Topiccomment getLatestCommentByTopicId(long topicId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("originalTopicId", topicId);
		String hql="from Topiccomment t where t.originalTopicId=:originalTopicId order by commentTime DESC limit 0,0";
		return  topicCommentDao.find(hql, params).get(0);
	}

	@Override
	public Long countTotalCommentByTopicId(long topicId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("originalTopicId", topicId);
		String hql="select count(*) from Topiccomment t where t.originalTopicId=:originalTopicId";
		return topicCommentDao.count(hql, params);
	}
	
}
